Completed
Push — master ( 3ca971...d2d9a7 )
by Sergey
02:11
created

RBAcModule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 41
dl 0
loc 52
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A forRoot 0 15 2
A forDynamic 0 21 1
1
import { DynamicModule, Global, Module } from '@nestjs/common';
2
import { RbacService } from './services/rbac.service';
3
import { ModuleRef, Reflector } from '@nestjs/core';
4
import { StorageRbacService } from './services/storage.rbac.service';
5
import { IStorageRbac } from './interfaces/storage.rbac.interface';
6
import { IDynamicStorageRbac } from './interfaces/dynamic.storage.rbac.interface';
7
8
@Global()
9
@Module({
10
  providers: [
11
    RbacService,
12
    StorageRbacService,
13
    Reflector,
14
  ],
15
  imports: [],
16
  exports: [
17
    RbacService,
18
  ],
19
})
20
export class RBAcModule {
21
  static forRoot(
22
    rbac: IStorageRbac,
23
    providers?: any[],
24
    imports?: any[],
25
  ): DynamicModule {
26
27
    return RBAcModule.forDynamic(
28
      /* tslint:disable */
29
      class {
30
        async getRbac(): Promise<IStorageRbac> {
31
          return rbac;
32
        };
33
      },
34
      providers,
35
      imports,
36
    );
37
  }
38
39
   static forDynamic(
40
    rbac: new () => IDynamicStorageRbac,
41
    providers?: any[],
42
    imports?: any[],
43
  ): DynamicModule {
44
    return {
45
      module: RBAcModule,
46
      providers: [
47
        ...(providers || []),
48
        rbac,
49
        {
50
          provide: StorageRbacService,
51
          useFactory: (moduleRef: ModuleRef, rbacService: IDynamicStorageRbac) => {
52
            return new StorageRbacService(moduleRef, rbacService);
53
          },
54
          inject: [ModuleRef, rbac],
55
        },
56
      ],
57
      imports: [
58
        ...(imports || []),
59
      ],
60
    };
61
  }
62
}
63